﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simulation.Mechanism;
using KeywordAuction;

namespace Simulation
{
    public class AuctionFactoryForChapter3 : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.AuctionMechanism = new GSPAuctionMechanism();
  
            for (int i = 0; i <3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new StrategyRaiseAll {  });
                advertiser.Strategies.Add(new StrategyDropAll { });
                advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}",i);
            }

            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost,locationCount:2);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = random.Next(20, 100);
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }
            
            return auctionHost;
        }
    }
}
